package com.wave.system.thread;

import com.wave.common.utils.spring.SpringUtils;
import com.wave.system.service.ISysToolBoardTaskService;
import com.wave.system.util.Modbus4jUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class PathPoint3ListenerThread implements Runnable {

    private static final Map<Integer, String> map = new HashMap<>();

    static {
        map.put(0, "1701");
        map.put(1, "1702");
        map.put(2, "1703");
        map.put(3, "1801");
        map.put(4, "1802");
        map.put(5, "1803");
    }

    private final ISysToolBoardTaskService sysToolBoardTaskService = SpringUtils.getBean(ISysToolBoardTaskService.class);

    @Override
    public void run() {
        while (true) {
            try {
                String result = Modbus4jUtils.readHoldingRegistersToString(1, 299, 78);
                sysToolBoardTaskService.updateToolBoardInfo(result, map);
                TimeUnit.MILLISECONDS.sleep(200);
            } catch (Exception e) {
                log.error("第三组工装板任务线体更新异常", e);
            }
        }
    }

}
